package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/1/23 13:31
 * @apiNote
 */

public class Test00434CountSegments {
    public static void main(String[] args) {
        String s = "Hello, my name  is John";
        System.out.println(countSegments(s));

    }

    public static int countSegments(String s) {
        int segmentCount = 0;
        for (int i = 0; i < s.length(); i++) {
            if ((i == 0 || s.charAt(i - 1) == ' ') && s.charAt(i) != ' ') {
                segmentCount++;
            }
        }
        return segmentCount;
    }
}
